package org.itboys.basetemplate.service;

import org.itboys.basetemplate.entity.ApplyInfo;
import org.itboys.member.entity.Member;
import org.itboys.member.service.MemberService;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
public class ApplyInfoService extends BaseService<ApplyInfo, Long> {

	private static final long serialVersionUID = -2792207845905508305L;
	
	@Autowired
	private MemberService memberService;
	
	@Resource(name="adminDS")
	private MongoDataSource dictDataSource;
	
	protected MongoDataSource getMongoDataSource() {
		return dictDataSource;
	}

	protected Class<ApplyInfo> getEntityClass() {
		return ApplyInfo.class;
	}

	//审核
	@Transactional("transactionManager")
	public void comfirm(Long id, Integer status) {
		ApplyInfo applyInfo = this.getById(id);
		Member member = memberService.getById(applyInfo.getMemberId());
		applyInfo.setStatus(status);
		//审核通过
		if(status == 1) {
			member.setIsView(1);
			memberService.update(member);
		}
		this.update(applyInfo);
	}

}
